package qlsl.androiddesign.view.subview.activityview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import qlsl.androiddesign.activity.subactivity.CommentActivity;
import qlsl.androiddesign.activity.subactivity.TrailerDetailActivity;
import qlsl.androiddesign.adapter.subadapter.CarDetailAdapter;
import qlsl.androiddesign.adapter.subadapter.RecruitReleasAdapter;
import qlsl.androiddesign.entity.otherentity.Trailer;
import qlsl.androiddesign.util.commonutil.ImageUtils;
import qlsl.androiddesign.util.runfeng.StringUtils;
import qlsl.androiddesign.util.runfeng.ToActivityUtil;
import qlsl.androiddesign.view.baseview.FunctionView;
import android.text.TextUtils;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.qlsl.androiddesign.kuaiwa.R;

/**
 * 快拖详情页<br/>
 * 需要传入的键：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
public class TrailDetailView extends FunctionView<TrailerDetailActivity> {

	protected List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

	protected ListView listView;

	public TrailDetailView(TrailerDetailActivity activity) {
		super(activity);
		setContentView(R.layout.activity_trailer_detail);
	}

	protected void initView(View view) {
		setTitle("详情");
		listView = findViewById(R.id.listView);

	}

	public Trailer getTrailDetailItem() {
		return (Trailer) activity.getIntent().getSerializableExtra("data");
	}

	protected void initData() {
		Trailer mTailer = getTrailDetailItem();
		if (mTailer != null) {
			TextView tv_name = findViewById(R.id.tv_name);
			ImageView iv_icon = findViewById(R.id.iv_icon);
			TextView tv_price = findViewById(R.id.tv_price);

			tv_name.setText(mTailer.getBusinessname());
			ImageUtils.circle(activity, mTailer.getPhoto(), iv_icon);
			tv_price.setText("");

		} else {
			return;
		}

		setListViewData(mTailer);

	}

	private void setListViewData(Trailer mTailer) {
		String[] names = new String[] { "司机姓名", "服务类型", "司机地址", "司机电话" };

		for (int index = 0; index < names.length; index++) {
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("name", names[index]);
			String content = null;
			if (index == 0) {
				content = mTailer.getServertype();
			} else if (index == 1) {
				content = mTailer.getAddress();
			} else if (index == 2) {
				content = mTailer.getMobile();
			} else if (index == 3) {
				content = mTailer.getBossname();
			}
			map.put("content", content);
			list.add(map);
		}
		notifyDataSetChanged();
	}

	protected void initListener() {

	}

	public <T> void showData(T... t) {

	}

	public <T> void showNoData(T... t) {

	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.assessment_again:
			doClickTVComment();
			// Trailer mTailer = getTrailDetailItem();
			// if (mTailer != null) {
			// String phone = mTailer.getMobile();
			// if (!TextUtils.isEmpty(phone)) {
			// ToActivityUtil.callPhoneActivity(activity, "" + phone);
			// } else {
			// showToast("对方未提供手机号");
			// }
			// }
			break;
		case R.id.comment:
			startActivity(CommentActivity.class);
			break;
		case R.id.tv_num_comment:// 咨询
			doClickTVComment();
			break;
		default:
			break;
		}

	}

	/**
	 * 拨打电话
	 */
	private void doClickTVComment() {
		if (StringUtils.isMobileNo(getTrailDetailItem().getMobile())) {
			ToActivityUtil.callPhoneActivity(activity, getTrailDetailItem()
					.getMobile());
		} else {
			showToast("对方提供手机号有误");
		}
	}

	protected void resetList(List<HashMap<String, String>> list_result) {
		list.clear();
		list.addAll(list_result);
	}

	protected void notifyDataSetChanged() {
		BaseAdapter adapter = (BaseAdapter) listView.getAdapter();
		if (adapter == null) {
			adapter = new CarDetailAdapter(activity, list);
			listView.setAdapter(adapter);
		} else {
			adapter.notifyDataSetChanged();
		}
	}
}
